package com.icss.mqsp.config;

import com.icss.mqsp.util.ResourcesUtil;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertyConfig
{
  private static Properties p = null;
  private static Map<String, Properties> map = null;
  private static String source = null;
  private static final String BASTPATH = "config/property";
  
  private PropertyConfig()
  {
    map = new HashMap();
    try
    {
      File file = ResourcesUtil.getResourceAsFile("config/property");
      if (file.isDirectory()) {
        for (int i = 0; i < file.listFiles().length; i++)
        {
          String fullName = file.listFiles()[i].getName();
          String fileName = fullName.substring(0, fullName.indexOf("."));
          
          map.put(fileName, ResourcesUtil.getResourceAsProperties("config/property/" + fullName));
        }
      }
    }
    catch (IOException ex)
    {
      ex.printStackTrace();
    }
  }
  
  public static PropertyConfig getInstance(String path)
  {
    source = path;
    return sdf;
  }
  
  public String getProperty(String key)
  {
    p = (Properties)map.get(source);
    
    return p.getProperty(key);
  }
  
  private static PropertyConfig sdf = new PropertyConfig();
}
